#include "vector_float.h"

//private
void vector_float::create_vector(int s){
	if (s == 0){
		size = 0;
		vptr = nullptr;
	}
	else if (s > 0){
		vptr = new float[s];
		size = s;
	}
	else{
		cout << "Error - Invalid size. Size must be above 0!" << endl;
		size = 0;
		vptr = nullptr;
	}
}

void vector_float::delete_vector(){
	delete[] vptr;
}


//public
void vector_float::set(float value, int index){
	if (index >= 0 && index < size){
		vptr[index] = value;
	}
	else{
		cout << "Error - Invalid index: " << index << "! Vector size is " << size << endl;
	}
}

void vector_float::read_from_keyboard(){
	float value;
	for (int i = 0; i < size; i++){
		cout << "Enter element #" << i << ": ";
		cin >> value;
		set(value, i);
	}
}

void vector_float::print(){
	cout << "[";
	for (int i = 0; i < size; i++){
		cout << vptr[i];
		if (i < size - 1){
			cout << ",";
		}
	}
	cout << "]" << endl;
}

vector_float & vector_float::operator=(vector_float& v){
	create_vector(v.size);
	for (int i = 0; i < v.size; i++){
		vptr[i] = v.vptr[i];
	}
	return *this;
}


//constructors
vector_float::vector_float()
{
	create_vector(0);
}

vector_float::vector_float(int s){
	create_vector(s);
}

vector_float::vector_float(vector_float& v){
	create_vector(v.size);
	for (int i = 0; i < v.size; i++){
		vptr[i] = v.vptr[i];
	}
}

//destructor
vector_float::~vector_float()
{
	delete_vector();
}
